package ar.com.ford.it.fullEconomics.persistence.dao.query;

import oracle.toplink.expressions.Expression;
import oracle.toplink.expressions.ExpressionBuilder;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesg01Plant;
import ar.com.ford.it.fullEconomics.persistence.dto.Teess01Supplier;
import com.ford.it.persistence.impl.toplink.CustomExpressionFactory;

public class SupplierbyNameFindQuery implements CustomExpressionFactory {

    public Expression createExpression(ExpressionBuilder builder,
                                       Object[] parameters) {
        Expression exp = null;
        Teess01Supplier supplier = (Teess01Supplier) parameters[0];
        
        String name = supplier.getEess01SupplierNameN();
        Teesg01Plant plant = supplier.getEess01PlantCodeC();

        exp = builder.get("eess01PlantCodeC").equal(plant);
        if (name != null) {
            exp = exp.and(builder.get("eess01SupplierNameN").toLowerCase().equal(
                    name.toLowerCase()));
        }
        return exp;
    }
}
